﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using Dqs_BLL;
using Dqs_DAL;
using Model;
using Sunny.UI;

namespace Dqs_UI
{
	public partial class frmStudent : UIForm
	{
		public frmStudent(StudentInfo student)
		{
			InitializeComponent();
			this._studentInfo = student;
		}
		StudentInfo _studentInfo { get; set; }
		Student_BLL student_BLL = new Student_BLL();
		Course_BLL course_BLL = new Course_BLL();

		private void uiButton1_Click(object sender, EventArgs e)
		{
			DialogResult = DialogResult.OK;
		}

		private void uiButton2_Click(object sender, EventArgs e)
		{
			if (Convert.ToInt32(cmbCourseName.SelectedValue) == -1)
			{
				MessageBox.Show("请先选择课程");
				return;
			}
			frmQuestion_Student student = new frmQuestion_Student(_studentInfo);
			student.ShowDialog(this);
		}



		private void frmStudent_Load(object sender, EventArgs e)
		{
			lblStudentInfo.Text = "你好," + _studentInfo.FullName + "同学";

			List<CourseInfo> list = course_BLL.GetCourses();
			list.Insert(0, new CourseInfo() { CourseName = "--请选择--", Id = -1 });
			//赋值
			cmbCourseName.DisplayMember = "CourseName";
			cmbCourseName.ValueMember = "Id";
			cmbCourseName.DataSource = list;

			uiLabel1.Text =  "座位号："+_studentInfo.AttendCount;

			lblStuNum.Text = _studentInfo.StuNum;
			lblQuestionNum.Text = _studentInfo.QuestionCount.ToString();
		}



		private void FrmUpdateSeat_FormClosed(object? sender, FormClosedEventArgs e)
		{

		}

		private void uiButton3_Click(object sender, EventArgs e)
		{
			StudentInfo student = _studentInfo;
			student.AttendCount = Convert.ToInt32(txtSeatNum.Text.Trim());
			student_BLL.UpdateStudentInfoById(student);
			uiLabel1.Text = "座位号：" + _studentInfo.AttendCount;
		}

		private void uiButton4_Click(object sender, EventArgs e)
		{
			StudentInfo student = _studentInfo;
			student.AttendCount = 0;
			student_BLL.UpdateStudentInfoById(student);
			uiLabel1.Text = "座位号：" + _studentInfo.AttendCount;
		}
	}
}
